package world.criver.stpathwriteto;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Random;

public class Main {
    public static void main(String[] args) {
        try {
            String qwe="";
            String[] asd;
            String path="data";
            for(String i:args){
                i=i.replaceAll("\"","");
                if(!i.contains(":"))continue;
                asd=i.split(":");
                if(asd.length!=2)continue;
                if(asd[0].equals("write_to_path"))path=asd[1];
                else qwe+="\""+asd[0]+"\":\""+asd[1]+"\",";
            }
            qwe="{"+qwe.substring(0,qwe.length()-1)+"}";
            File f = new File(path);
            if (!f.exists()) f.mkdirs();
            f = new File(path+"/" + System.currentTimeMillis()+(new Random().nextInt(900_000)+100_000) +".json");
            BufferedWriter wr=new BufferedWriter(new FileWriter(f));
            wr.write(qwe);
            wr.close();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}